SI649 W23 Altair Homework #4¶
Overview¶
We'll focus on maps and cartrographic visualization. In this lab, you will practice:
- Point Maps
- Symbol Maps
- Choropleth maps
- Interactions with maps
Lab Instructions¶
- Save, rename, and submit the ipynb file (use your username in the name).
- Complete all the checkpoints, to create the required visualization at each cell.
- Run every cell (do Runtime -> Restart and run all to make sure you have a clean working version), print to pdf, submit the pdf file.
- If you end up stuck, show us your work by including links (URLs) that you have searched for. You'll get partial credit for showing your work in progress.
In [41]:
import pandas as pd
import altair as alt
from vega_datasets import data
alt.data_transformers.disable_max_rows()
df = pd.read_csv('https://raw.githubusercontent.com/dallascard/si649_public/main/altair_hw4/airports.csv')
url = "https://raw.githubusercontent.com/dallascard/si649_public/main/altair_hw4/small-airports.json"
Visualization 1: Dot Density Map¶
Description of the visualization:
We want to visualize the density of small airports in the world. Each small airport is represented by a dot. The visualization has two layers:
- The base layer shows the outline of the world map.
- The point map shows different small airports.
- The tooltip shows the name of the airport.
Hint:
- How can we show continents on the map? Which object can be used from the json dataset ?
- How can we show only small airports on the map?
In [42]:
df = df[df['type']=='small_airport']
world_map = alt.topo_feature(url, feature='continent')
base = alt.Chart(world_map).mark_geoshape(
fill='lightgray'
).project('mercator')
points = alt.Chart(df).mark_circle(size=14, color='red').encode(
longitude='longitude_deg:Q',
latitude='latitude_deg:Q',
tooltip='name:N'
)
map_vis = base + points
map_vis.properties(width=900, height=800)
Out[42]: